#include "optionsdialog.h"
#include "ui_optionsdialog.h"

OptionsDialog::OptionsDialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::OptionsDialog)
{
    m_ui->setupUi(this);
}

OptionsDialog::~OptionsDialog()
{
    delete m_ui;
}

void OptionsDialog::updateActive()
{
    bool active = m_ui->useProxyBox->isChecked();
    bool auth_active = m_ui->useProxyAuthBox->isChecked();
    m_ui->proxyHostEdit->setEnabled(active);
    m_ui->proxyPortBox->setEnabled(active);
    m_ui->useProxyAuthBox->setEnabled(active);
    m_ui->proxyUserEdit->setEnabled(active && auth_active);
    m_ui->proxyPasswordEdit->setEnabled(active && auth_active);
}

void OptionsDialog::updateSettings()
{
    emit saveSettings();
}

QString OptionsDialog::getEmail()
{
    return m_ui->emailEdit->text();
}

void OptionsDialog::setEmail(QString email)
{
    m_ui->emailEdit->setText(email);
}

QString OptionsDialog::getPassword()
{
    return m_ui->passwordEdit->text();
}

void OptionsDialog::setPassword(QString password)
{
    return m_ui->passwordEdit->setText(password);
}

int OptionsDialog::getTimeout()
{
    return m_ui->timeoutBox->value();
}

void OptionsDialog::setTimeout(int timeout)
{
    m_ui->timeoutBox->setValue(timeout);
}

bool OptionsDialog::getUseProxy()
{
    return m_ui->useProxyBox->isChecked();
}

void OptionsDialog::setUseProxy(bool use)
{
    m_ui->useProxyBox->setChecked(use);
}

QString OptionsDialog::getProxyHost()
{
    return m_ui->proxyHostEdit->text();
}

void OptionsDialog::setProxyHost(QString host)
{
    return m_ui->proxyHostEdit->setText(host);
}

int OptionsDialog::getProxyPort()
{
    return m_ui->proxyPortBox->value();
}

void OptionsDialog::setProxyPort(int port)
{
    m_ui->proxyPortBox->setValue(port);
}

bool OptionsDialog::getUseProxyAuth()
{
    return m_ui->useProxyAuthBox->isChecked();
}

void OptionsDialog::setUseProxyAuth(bool use)
{
    m_ui->useProxyAuthBox->setChecked(use);
}

QString OptionsDialog::getProxyUser()
{
    return m_ui->proxyUserEdit->text();
}

void OptionsDialog::setProxyUser(QString user)
{
    return m_ui->proxyUserEdit->setText(user);
}

QString OptionsDialog::getProxyPassword()
{
    return m_ui->proxyPasswordEdit->text();
}

void OptionsDialog::setProxyPassword(QString password)
{
    return m_ui->proxyPasswordEdit->setText(password);
}

void OptionsDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
